package cn.newtest.common.dbutils.dialect;

/**
 * MySQL的专用分页语句
 * 
 * @author WangChui(baiyibing@gmail.com)
 * @version 1.0 TODO
 * 
 */
public class MySQLDialect implements DBDialect {
	public boolean supportsLimit() {
		return true;
	}

	public String getCountString(String sql) {
		StringBuffer countSelect = new StringBuffer(100);
		countSelect.append("select count(*) from (");
		countSelect.append(sql);
		countSelect.append(" ) totalTable ");
		return countSelect.toString();
	}

	public String getLimitString(String sql) {
		StringBuffer pagingSelect = new StringBuffer(100);
		pagingSelect.append(sql);
		pagingSelect.append(" limit ?, ?");
		return pagingSelect.toString();
	}

	public String getLimitString(String sql, int begin, int end, String orderByKey) {
		StringBuffer pagingSelect = new StringBuffer(100);
		pagingSelect.append(sql);
		pagingSelect.append(" limit " + begin + ", " + end);
		return pagingSelect.toString();
	}
}
